import { Body, Controller, Get, Post, UseGuards, UseInterceptors } from '@nestjs/common';
import { Expose } from 'class-transformer';
import { IsNotEmpty, IsString } from 'class-validator';
import { Can, CheckPolicies } from '../decorators/casl.decorator';
import { Serialize } from '../decorators/serialize.decorator';
import { CaslGuard } from '../guards/casl.guard';
import { Logs } from './logs.entity';
import { Action } from '../enum/actionn.enum';
// import { SerializeInterceptor } from 'src/interceptors/serialize.interceptor';

class CreateLogsDto {
  @IsString()
  id: string;

  @IsString()
  @IsNotEmpty()
  msg: string;
}

class PublicLogsDto {
  @Expose()
  msg: string;
}

@Controller('logs')
@UseGuards(CaslGuard)
@CheckPolicies(ability => ability.can(Action.Read, Logs))
export class LogsController {
  @Get()
  @Can(Action.Read, Logs)
  getLogs(){
    return 'logs'
  }

  @Post()
  @Serialize(PublicLogsDto)
  @Can(Action.Create, Logs)
  // @UseInterceptors(new SerializeInterceptor(PublicLogsDto))
  createLogs(@Body() dto: CreateLogsDto){
    console.log("🚀 ~ LogsController ~ createLogs ~ dto:", dto)
    return dto;
  }
}
